package spotGUI.GUIElements.MarkerGUI;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import spotGUI.utils.EmptyContentAreaButton;

public class StarButton extends EmptyContentAreaButton {
	
	private StarButton previous;
	private StarButton next = null;
	
	public StarButton (StarButton prev, final int mark, final StarMarkerPanel panel) {
		super(StarButton.class.getResource("/images/Icons/32x32/empty_favorite.png"), "");
		setSelectedIcon(new ImageIcon(StarButton.class.getResource("/images/Icons/32x32/favorite.png")));
		
		this.previous = prev;
		if (this.previous != null) {
			this.previous.setNext (this);
		}
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				super.mouseClicked(e);
				setSelected(false);
				setSelected(true);
				panel.setCurrentMark(mark);
			}
		});
	}
	
	@Override
	public void setSelected(boolean b) {
		super.setSelected(b);
		if (b == true && previous != null) {
			previous.setSelected(true);
		} else if (b == false && next != null){
			next.setSelected(false);
		}
	}
	
	private void setNext (StarButton next) {
		this.next = next;
	}
}